﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Xml;
using System.Xml.Serialization;


namespace Interface
{
    
    class Program
    {


        static void Main(string[] args)
        {

            Client c = new Client();
            c.username = "toto in parameters";
            c.password = "pass";
            c.screenname = "cacaboy";
            //c.server = "http://172.16.7.11:8080";
            //c.server = "http://localhost";
            
            Console.WriteLine("\n");
            String ret = c.CreateUser("toto", "Darktoto", "secret");
            Console.WriteLine("create_user");
            Console.WriteLine(ret);

            TextWriter textWriter = new StreamWriter(@"C:\Documents and Settings\info_seb\Bureau\testgoo.xml");
            //TextWriter textWriter = new StreamWriter(@"C:\Documents and Settings\ssuner\Bureau\testgoo.xml");
           
            
            textWriter.Write(ret);
            textWriter.Close();
            Console.WriteLine("createboard:\n");
            Console.WriteLine(c.CreateBoard("totohome", "toto", "noob", "19X19", true));
            Console.WriteLine("invite:\n");
            Console.WriteLine(c.Invite("totohome","bird"));
            Console.WriteLine("request:\n");
            Console.WriteLine(c.Request("test board"));
            Console.WriteLine("move:\n");
            Console.WriteLine(c.Move(3,4,"test board"));
            Console.WriteLine("\n");


            Console.WriteLine("test deserilization");
            

            //working fine
            /*XmlSerializer deser = new XmlSerializer(typeof(goimerir));
            VersionPostUsers test;
            test = (VersionPostUsers)deser.Deserialize(new StringReader(ret));
           
            Console.WriteLine("result"+test.user_create.fullname.val);
            */



            //working fine too but be carefull with invisible caracters in the file 
            /*XmlSerializer deser = new XmlSerializer(typeof(goimerir));
            TextReader read = new StreamReader(@"C:\Documents and Settings\info_seb\Bureau\testdeseriallirefichier.xml");
           
            VersionUrl test;
            test = (VersionUrl)deser.Deserialize(read);
            Console.WriteLine("result" + test.urls.url.name);
            Console.WriteLine("result" + test.urls.url.href);
            */
            //c.test();
            XmlSerializer deser = new XmlSerializer(typeof(goimerir));
            TextReader read = new StreamReader(@"C:\Documents and Settings\info_seb\Bureau\testdeseriallirefichier.xml");

            VersionUsers test;
            test = (VersionUsers)deser.Deserialize(read);
            Console.WriteLine("nb " + test.users.Count);
            Console.WriteLine("resultfull0 " + test.users[0].fullname);
            Console.WriteLine("resultfull1 " + test.users[1].fullname);
            Console.WriteLine("resultnam " + test.users[1].name);
            Console.WriteLine("resulturl" + test.users[1].url);
            



            //dont work,invisible bytes suspected
            /*
            String ee=c.test();

            XmlSerializer deser = new XmlSerializer(typeof(VersionUrl));
            String enter = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<goimerir version=\"1.0\">\n<urls>\n<url name=\"baseUrl\" href=\"http://api.goimerir.com\" />\n</urls>\n</goimerir>";
            textWriter = new StreamWriter(@"C:\Documents and Settings\info_seb\Bureau\testdeserial.xml");
            textWriter.Write(enter);
            textWriter.Close();
             VersionUrl test;
             
             test = (VersionUrl)deser.Deserialize(new StringReader(enter));
            
           
            Console.WriteLine("result"+test.urls.url.href);
             */

            //creer board
            //move22
            //move22


            Console.WriteLine("server response");

            //c.test2();

            
            //172.31.1.151
            //Kyozenken-PC
            //Console.WriteLine(c.HttpGet("http://localhost"));
            //c.server = "http://172.16.7.11:8080";
            //c.server="http://localhost";
            //c.server = "http://192.168.1.10:8080";
            //c.server = "http://172.16.7.3:8080";

            Console.WriteLine(c.CheckConfig("http://172.31.1.148:8080"));
            //Console.WriteLine(c.CreateUser());
            c.server = "http://172.31.1.148:8080";//remy
            Console.WriteLine("réponse recue:");
            //String rr=c.ListUsers();
            //String rr = c.RetrieveBoards();
            //Console.WriteLine(rr);

            /*test = (VersionUsers)deser.Deserialize(new StringReader(rr));
            Console.WriteLine("j'extrait le nom du 1er user:");
            Console.WriteLine(test.users[0].name);*/
            
            //Console.WriteLine(c.CheckConfig("http://localhost"));
            //Console.WriteLine(c.CheckConfig("https://mwa2.mipih.fr/"));
            Console.WriteLine(c.server);


           /* Console.WriteLine("create board:\n");
            Console.WriteLine(c.CreateBoard( "boardtest", "noob", "9x9", true));
            Console.WriteLine("move1 :\n");
            Console.WriteLine(c.Move(3, 2, "boardtest"));
            Console.WriteLine("move 2\n");
            Console.WriteLine(c.Move(3, 2, "boardtest"));*/



           

            char s = System.Console.ReadKey(true).KeyChar;
        }

        

   
        





    }
}
